home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The 640 MEG Shareware Studio 2
/
The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO
/
clang
/
nn.zip
/
SEQUENCE.C
< prev
next >
Wrap
C/C++ Source or Header
|
1989-12-31
|
10KB
|
504 lines
/*
* read presentation sequence file
*/
#include "config.h"
#include "debug.h"
export group_header *group_sequence;
export char *read_mail = NULL;
export int also_unsub_groups = 0;
export int also_subgroups = 1;
static int seq_break_enabled = 1; /* !! enabled */
static group_header *tail_sequence = NULL;
static group_header *final_sequence = NULL;
static int gs_more_groups;
only_folder_args(args)
char **args;
{
register char *arg;
while (arg = *args++) {
if (*arg == '+' || *arg == '~' || *arg == '/') continue;
if (file_exist(arg, "fr")) continue;
return 0;
}
return 1;
}
named_group_sequence(groups)
char **groups;
{
register group_header *gh;
group_header *get_group_search();
register char *group;
int found, any, errors;
group_sequence = NULL;
also_subgroups = 0;
any = errors = 0;
while (group = *groups++) {
if (gh = lookup(group)) {
if (gh->group_flag & G_DONE) continue;
any++;
enter_normal(gh);
continue;
}
if (file_exist(group, "fr")) {
faked_entry(group, G_FOLDER);
any++;
continue;
}
if (*group == '+' || *group == '~') {
char exp_file[FILENAME];
group_header fake_group;
current_group = &fake_group;
fake_group.group_name = group;
group_file_name = NULL;
if (expand_file_name(exp_file, group) && file_exist(exp_file, "fr")) {
faked_entry(copy_str(exp_file), G_FOLDER);
any++;
continue;
}
printf("Folder %s not found\n", group); fl;
errors++;
continue;
}
found = 0;
start_group_search(group);
while (gh = get_group_search()) {
gh->group_flag |= G_DONE;
if ((gh->group_flag & G_SUBSCRIPTION) == 0 && !also_unsub_groups)
continue;
found++;
enter_normal(gh);
}
if (!found) {
printf("Group %s not found\n", group); fl;
errors++;
} else
any++;
}
end_sequence();
if (errors) user_delay(2);
return any;
}
FILE *loc_seq_hook = NULL; /* sequence in local "init" file */
FILE *glob_seq_hook = NULL; /* sequence in global "init" file */
normal_group_sequence()
{
register group_header *gh;
group_sequence = NULL;
gs_more_groups = 1;
/* visit_p_f returns non-zero if terminated by !! */
if (visit_presentation_file(nn_directory, "seq", loc_seq_hook))
goto final;
if (visit_presentation_file(lib_directory, "sequence", glob_seq_hook))
goto final;
Loop_Groups_Sorted(gh) {
if (gh->group_flag & G_DONE) continue;
if ((gh->group_flag & G_SUBSCRIPTION) == 0 && !also_unsub_groups)
continue;
enter_normal(gh);
}
final:
if (final_sequence) {
enter_normal(final_sequence);
tail_sequence = NULL;
}
#ifdef MAIL_READING
mail_check();
#endif
end_sequence();
}
static end_sequence()
{
register group_header *gh, *backp;
register int seq_ix;
if (tail_sequence)
tail_sequence->next_group = NULL;
/* set up backward pointers */
backp = NULL;
gh = group_sequence;
seq_ix = 0;
while (gh) {
gh->preseq_index = ++seq_ix;
gh->prev_group = backp;
backp = gh;
gh = gh->next_group;
}
#ifdef SEQ_DUMP
if (Debug & SEQ_DUMP) {
for (gh = group_sequence; gh; gh = gh->next_group)
printf("%s\t", gh->group_name);
putchar(NL);
nn_exit(0);
}
#endif
}
#ifdef MAIL_READING
static mail_check()
{
static group_header mail_group;
struct stat st;
if (read_mail == NULL) return;
if (stat(read_mail, &st) < 0) return;
if (st.st_size == 0 || st.st_mtime < st.st_atime) return;
mail_group.group_name = read_mail;
gh->group_flag = G_FOLDER | G_MAILBOX | G_READ;
/* "invent" an unread article for read_news */
gh->last_article = 1;
gh->last_l_article = 2;
if (tail_sequence) {
mail_group.next_group = group_sequence;
group_sequence = mail_group;
} else
enter_normal(&mail_group);
}
#endif
static visit_presentation_file(directory, seqfile, hook)
char *directory, *seqfile;
FILE *hook;
{
import int group_name_args;
register FILE *sf;
register c;
register group_header *gh;
group_header *get_group_search();
char group[FILENAME];
char savefile[FILENAME], *dflt_save, *enter_macro;
extern char *parse_enter_macro();
register char *gp;
int mode;
#define SHOW_NORMAL 0 /* : put this in at current pos */
#define SHOW_NEVER 1 /* ! : ignore these groups */
#define SHOW_FIRST 2 /* < : show these groups first */
#define SHOW_LAST 3 /* > : show this as late as possible */
#define SHOW_MODES " !<>"
if (gs_more_groups == 0) return 0;
if (hook != NULL)
sf = hook; /* hook to init file */
else
if ((sf = open_file(relative(directory, seqfile), OPEN_READ)) == NULL)
return 0;
#ifdef SEQ_TEST
if (Debug & SEQ_TEST)
printf("Sequence file %s/%s\n", directory, seqfile);
#endif
mode = SHOW_NORMAL;
savefile[0] = NUL;
while (gs_more_groups) {
if ((c = getc(sf)) == EOF) break;
if (!isascii(c) || isspace(c)) continue;
switch (c) {
case '!':
if (mode == SHOW_NEVER && seq_break_enabled) {
fclose(sf);
return 1;
}
mode = SHOW_NEVER;
continue;
case '<':
mode = SHOW_FIRST;
continue;
case '>':
mode = SHOW_LAST;
continue;
case '@':
seq_break_enabled = 0;
mode = SHOW_NORMAL;
continue;
case '#':
do c = getc(sf);
while (c != EOF && c != NL);
mode = SHOW_NORMAL;
continue;
}
gp = group;
do {
*gp++ = c;
c = getc(sf);
} while (c != EOF && isascii(c) && !isspace(c));
*gp = NUL;
while (c != EOF && (!isascii(c) || isspace(c))) c = getc(sf);
if (c == '+' || c == '~' || c == '/') {
gp = savefile;
if (c == '+') {
c = getc(sf);
if (c == EOF || (isascii(c) && isspace(c)))
goto use_same_savefile;
*gp++ = '+';
}
do {
*gp++ = c;
c = getc(sf);
} while (c != EOF && isascii(c) && !isspace(c));
*gp = NUL;
dflt_save = savefile[0] ? copy_str(savefile) : NULL;
} else
dflt_save = NULL;
use_same_savefile:
while (c != EOF && (!isascii(c) || isspace(c))) c = getc(sf);
if (c == '(') {
enter_macro = parse_enter_macro(sf, getc(sf));
} else {
enter_macro = NULL;
if (c != EOF) ungetc(c, sf);
}
start_group_search(group);
while (gh = get_group_search()) {
gh->group_flag |= G_DONE;
gh->save_file = dflt_save;
if (gh->enter_macro == NULL) /* not set by "on entry" */
gh->enter_macro = enter_macro;
if (group_name_args == 0 &&
(gh->group_flag & G_SUBSCRIPTION) == 0 && !also_unsub_groups)
continue;
#ifdef SEQ_TEST
if (Debug & SEQ_TEST && mode != SHOW_NORMAL)
printf("SEQ(%c), %s\n", SHOW_MODES[mode], gh->group_name);
#endif
switch (mode) {
case SHOW_FIRST:
if (tail_sequence) {
gh->next_group = group_sequence;
group_sequence = gh;
break;
}
/* fall thru */
case SHOW_NORMAL:
enter_normal(gh);
break;
case SHOW_NEVER:
break;
case SHOW_LAST:
gh->next_group = final_sequence;
final_sequence = gh;
break;
}
}
mode = SHOW_NORMAL;
}
fclose(sf);
return 0;
}
static enter_normal(gh)
group_header *gh;
{
gh->group_flag |= G_DONE;
if (tail_sequence)
tail_sequence->next_group = gh;
else
group_sequence = gh;
tail_sequence = gh;
#ifdef SEQ_TEST
if (Debug & SEQ_TEST)
printf("SEQ(NORMAL) %s\n", gh->group_name);
#endif
}
static faked_entry(name, flag)
char *name;
int32 flag;
{
group_header *gh;
gh = (group_header *)calloc(1, sizeof(group_header));
mem_check((char *)gh, 1, "group header");
gh->group_name = name;
gh->group_flag = flag | G_READ;
/* "invent" an unread article for read_news */
gh->last_article = 1;
gh->last_l_article = 2;
enter_normal(gh);
}
static char *gs_group;
static int gs_length, gs_index, gs_mode;
static group_header *gs_only_group = NULL;
#define GS_PREFIX0 0 /* group (or group*) */
#define GS_PREFIX 1 /* group. */
#define GS_SUFFIX 2 /* .group */
#define GS_INFIX 3 /* .group. */
#define GS_NEW_GROUP 4 /* new group */
#define GS_ALL 5 /* all / . */
start_group_search(group)
char *group;
{
char *dot;
int last;
gs_index = master.number_of_groups;
if ((last = strlen(group) - 1) < 0) return;
if (group[last] == '*')
group[last] = NUL;
else
if (!also_subgroups && (gs_only_group = lookup(group)) != NULL)
return;
if (strcmp(group, "NEW") == 0) {
gs_mode = GS_NEW_GROUP;
gs_length = 0;
} else
if (strcmp(group, "all") == 0 || strcmp(group, ".") == 0) {
gs_mode = GS_ALL;
gs_length = 0;
} else {
gs_mode = GS_PREFIX0;
if (strncmp(group, "all.", 4) == 0) group += 3;
if (*group == '.') gs_mode = GS_SUFFIX;
if ((dot = strrchr(group, '.')) != NULL && dot != group) {
if (dot[1] == NUL || strcmp(dot+1, "all") == 0) {
dot[1] = NUL;
gs_mode = (gs_mode == GS_SUFFIX) ? GS_INFIX : GS_PREFIX;
}
}
gs_length = strlen(group);
gs_group = group;
}
gs_index = 0;
gs_more_groups = 0;
}
group_header *get_group_search()
{
register group_header *gh;
register int c, tail;
if (gs_only_group != NULL) {
gh = gs_only_group;
gs_only_group = NULL;
if (gh->group_flag & (G_DONE | G_NO_DIRECTORY)) return NULL;
return gh;
}
while (gs_index < master.number_of_groups) {
gh = sorted_groups[gs_index++];
if (gh->group_flag & (G_DONE | G_NO_DIRECTORY)) continue;
gs_more_groups++;
if ((tail = gh->group_name_length - gs_length) < 0) continue;
switch (gs_mode) {
case GS_NEW_GROUP:
if ((gh->group_flag & G_NEW) == 0) continue;
break;
case GS_PREFIX0:
if ((c = (gh->group_name)[gs_length]) != NUL && c != '.') continue;
case GS_PREFIX:
if (strncmp(gh->group_name, gs_group, gs_length)) continue;
break;
case GS_SUFFIX:
if (strcmp(gh->group_name + tail, gs_group)) continue;
break;
case GS_INFIX:
user_error(".name. notation not supported (yet)");
break;
case GS_ALL:
break;
}
gs_more_groups--;
return gh;
}
return NULL;
}